﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.Data;
using System.Runtime.Serialization;
using ControlService.DataModel;
using BLLService;

namespace ControlService
{
    /// <summary>
    /// 公共契约
    /// </summary>
    [ServiceContract]
    public interface ICommonContract
    {
        #region 系统相关

        /// <summary>
        /// 根据页面和控件名称得到页面字段信息
        /// </summary>
        /// <param name="page">页面名称</param>
        /// <param name="ctl">控件名称</param>
        /// <returns></returns>
        [OperationContract]
        DataTable GetColumnByPageAndCtl(string page, string ctl, string guid, ref bool isLogin);

        [OperationContract]
        string GetColumnByPageAndCtls(string page, string ctls, string guid, ref bool isLogin);

        /// <summary>
        /// 得到Main页面分页数据
        /// </summary>
        /// <param name="pager"></param>
        /// <returns></returns>
        [OperationContract]
        ReturnPageData GetPageList(Pager pager, string guid, ref bool isLogin);

        /// <summary>
        /// 根据页面和控件得到页面控件实体
        /// </summary>
        /// <param name="page"></param>
        /// <param name="ctl"></param>
        /// <returns></returns>
        [OperationContract]
        String GetSys5a00(string page, string ctl, string guid, ref bool isLogin);

        /// <summary>
        /// 公用的保存方法
        /// </summary>
        /// <param name="callFun">保存时候调用的业务逻辑层的方法</param>
        /// <param name="data">Json字符串</param>
        /// <returns></returns>
        [OperationContract]
        String Save(string callFun, string data, string action, string guid, ref bool isLogin);

        /// <summary>
        /// 公用的保存方法
        /// </summary>
        /// <param name="callFun">保存时候调用的业务逻辑层的方法</param>
        /// <param name="data">概要Json字符串</param>
        /// <returns></returns>
        [OperationContract]
        String SaveDtl(string callFun, string data, string action, DataTable dtldata, DataTable deldata, string guid, ref bool isLogin);

        /// <summary>
        /// 根据where得到Table集合
        /// </summary>
        /// <param name="callFun"></param>
        /// <param name="where"></param>
        /// <param name="guid"></param>
        /// <param name="isLogin"></param>
        /// <returns></returns>
        [OperationContract]
        DataTable[] GetTables(string callFun, string where, string guid, ref bool isLogin);
     
        /// <summary>
        /// 加载修改数据
        /// </summary>
        /// <param name="page"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        [OperationContract]
        DataTable LoadEditData(string page, string action, string ctl, string where, string guid, ref bool isLogin);

        /// <summary>
        /// 得到PopWin的数据
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        [OperationContract]
        string GetPopData(string tableName, string fields, string otherFieldName, string order, string where, string otherWhere, int rownum, string guid, ref bool isLogin);

        /// <summary>
        /// 得到PopItem对象
        /// </summary>
        /// <param name="popno"></param>
        /// <returns></returns>
        [OperationContract]
        PopItem GetPopItem(string popno, string guid, ref bool isLogin);

        /// <summary>
        /// 用户的权限列表
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        string GetPermision(string guid, ref bool isLogin);

        /// <summary>
        /// 判断表中的数据是否存在
        /// </summary>
        /// <param name="tbName"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        [OperationContract]
        bool DataInDb(string tbName, string where, string guid, ref bool isLogin);

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <returns>代码|返回消息</returns>
        [OperationContract]
        string Login(String userName, String pwd, string mac, bool mk);

        /// <summary>
        /// 等到版本列表
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        string GetVesionList();

        /// <summary>
        /// 下线
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        string LoginOut(string guid);

        /// <summary>
        /// 执行数据库的函数
        /// </summary>
        /// <param name="key"></param>
        /// <param name="where"></param>
        /// <param name="guid"></param>
        /// <param name="isLogin"></param>
        /// <returns></returns>
        [OperationContract]
        string ExecFun(string key, string where, string guid, ref bool isLogin);

        /// <summary>
        /// 返回首行首列
        /// </summary>
        /// <param name="key"></param>
        /// <param name="where"></param>
        /// <param name="guid"></param>
        /// <param name="isLogin"></param>
        /// <returns></returns>
        [OperationContract]
        string ExecFunScalar(string key, string where, string guid, ref bool isLogin);

        /// <summary>
        /// 得到权限列表
        /// </summary>
        /// <param name="modulecode"></param>
        /// <param name="guid"></param>
        /// <param name="isLogin"></param>
        /// <returns></returns>
        [OperationContract]
        string GetActionList(string modulecode, string guid, ref bool isLogin);

        [OperationContract]
        string Exchange(string key);

        [OperationContract]
        DataTable GetSession(BLLService.Pager pager, string guid, ref bool isLogin);
        #endregion
    }

    // 使用下面示例中说明的数据协定将复合类型添加到服务操作
    [DataContract]
    public class DataContractBase
    {
        private string _vesion;

        /// <summary>
        /// 总记录数
        /// </summary>
        [DataMember]
        public string Vesion
        {
            get { return _vesion; }
            set { _vesion = value; }
        }
    }
}
